//
//  EJSOrderOperationTableViewCell.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/1/3.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSOrderOperationTableViewCell.h"
#import "EJSOrderModel.h"

@implementation EJSOrderOperationTableViewCell{
    EJSOrderModel *_orderModel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setOderModel:(EJSOrderModel *)orderModel{
    _orderModel = orderModel;
    
    self.goodsCountLabel.text = [NSString stringWithFormat:@"共%lu件",(unsigned long)orderModel.goods.count];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"应付总额：€%.2f",orderModel.totalAmount.floatValue]];
    [attr addAttribute:NSForegroundColorAttributeName value:AppPriceTextColor range:NSMakeRange(5, attr.length - 5)];
    self.orderPriceLabel.attributedText = attr;
    
    self.leftButton.hidden = YES;
    self.rightButton.hidden = YES;
    
    [self.leftButton setTitle:@"" forState:UIControlStateNormal];
    [self.leftButton setTitleColor:UIColorFromRGB(0x3C4151) forState:UIControlStateNormal];
    self.leftButton.borderColor = UIColorFromRGB(0x3C4151);
    
    [self.rightButton setTitle:@"" forState:UIControlStateNormal];
    [self.rightButton setTitleColor:UIColorFromRGB(0x3C4151) forState:UIControlStateNormal];
    self.rightButton.borderColor = UIColorFromRGB(0x3C4151);
    
    // - 1 已取消   1待付款 2 已付款 3 已发货 4 已完成 5 已评价 nil为全部
    if(orderModel.flag.integerValue == 1){
        self.leftButton.hidden = NO;
        self.rightButton.hidden = NO;
        
        [self.rightButton setTitle:@"立即付款" forState:UIControlStateNormal];
        [self.rightButton setTitleColor:AppMainColor forState:UIControlStateNormal];
        self.rightButton.borderColor = AppMainColor;
        
        [self.leftButton setTitle:@"取消订单" forState:UIControlStateNormal];
    }else if(orderModel.flag.integerValue == 2){
        self.leftButton.hidden = YES;
        self.rightButton.hidden = YES;
        
        [self.rightButton setTitle:@"取消订单" forState:UIControlStateNormal];
    }else if(orderModel.flag.integerValue == 3){
        self.leftButton.hidden = NO;
        self.rightButton.hidden = NO;
        
        [self.leftButton setTitle:@"查看物流" forState:UIControlStateNormal];
        [self.rightButton setTitle:@"确认收货" forState:UIControlStateNormal];
    }else if(orderModel.flag.integerValue == 4){
        self.leftButton.hidden = YES;
        self.rightButton.hidden = NO;
        
        [self.rightButton setTitle:@"评价" forState:UIControlStateNormal];
    }else{
        self.leftButton.hidden = YES;
        self.rightButton.hidden = YES;
    }
}
- (IBAction)orderOperationAction:(UIButton *)sender {
    NSString *operation = [sender titleForState:UIControlStateNormal];
    
    if([operation isEqualToString:@"立即付款"]){
        if([self.delegate respondsToSelector:@selector(payFoyOrder:)]){
            [self.delegate payFoyOrder:_orderModel];
        }
    }else if ([operation isEqualToString:@"查看物流"]){
        if([self.delegate respondsToSelector:@selector(checkLogisticsOrder:)]){
            [self.delegate checkLogisticsOrder:_orderModel];
        }
    }else if ([operation isEqualToString:@"取消订单"]){
        if([self.delegate respondsToSelector:@selector(cancelOrder:)]){
            [self.delegate cancelOrder:_orderModel];
        }
    }else if ([operation isEqualToString:@"确认收货"]){
        if([self.delegate respondsToSelector:@selector(receivedOrder:)]){
            [self.delegate receivedOrder:_orderModel];
        }
    }else if ([operation isEqualToString:@"评价"]){
        if([self.delegate respondsToSelector:@selector(commentOrder:)]){
            [self.delegate commentOrder:_orderModel];
        }
    }
}

@end
